﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

//有向图


vector<vector<pair<int, int>>> VertexCreat(int n, int e)
{
	vector<vector<pair<int, int>>> graph;
	graph.resize(n);
	int a, b, c;
	while(e--)
	{
		cin >> a >> b >> c;
		graph[a].push_back(make_pair(b, c));
	}
	return graph;
}

void GraphPrint(vector<vector<pair<int, int>>>graph)
{
	for (size_t i = 0; i < graph.size(); i++)
	{
		if (!graph[i].empty())
		{
			cout << i << ':';
			sort(graph[i].begin(), graph[i].end());
			for (size_t j = 0; j < graph[i].size(); j++)
			{
				cout << '(' << i << ',' << graph[i][j].first << ',' << graph[i][j].second << ')';
			}
			cout << endl;
		}
	}
}
struct Vertex { //顶点表中结点的结构
	int VerName; //顶点名称
	Edge* adjacent;//边链表的头指针
}; 
struct Edge { //边结点的结构
	int VerAdj; //邻接顶点序号
	int cost; //边的权值
	Edge* link; //指向下一个边结点的指针
};


int main()
{
	int n, e;
	cin >> n >> e;
	vector<vector<pair<int, int>>> graph = VertexCreat(n, e);
	GraphPrint(graph);
	return 0;
}
